package top.meeting.room.module.book.listener;

import com.xiaoleilu.hutool.util.ThreadUtil;
import net.dreamlu.event.core.ApplicationListener;
import net.dreamlu.event.core.Listener;
import top.meeting.room.common.kit.PushMsgKit;
import top.meeting.room.common.kit.WxKit;
import top.meeting.room.module.book.event.ApproveEvent;
import top.meeting.room.module.book.model.Book;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * 我有故事，你有酒么？
 * JKhaled created by yunqisong@foxmail.com 2017/9/17
 * FOR : 审批后发送消息事件
 */
@Listener(order = 1, enableAsync = true)
public class PushMsgToUser implements ApplicationListener<ApproveEvent> {

    @Override
    public void onApplicationEvent(ApproveEvent event) {
        Book book = (Book) event.getSource();
        String str = event.getStr();
        // 给预订人发送推送
        WxKit.sendMessage(book.msgForBookUser(str), Arrays.asList(book.getUser() == null ? "" : book.getUser().getOpenId()));
    }
}
